/**
 * Created by Administrator on 2017/5/24 0024.
 */

const ExtractTextPlugin = require('extract-text-webpack-plugin');


exports.loadCSS = ({include, exclude} = {}) => ({
   module: {
       rules: [
           {
               test: /\.css$/,
               include,
               exclude,

               use: [
                   'style-loader',
                   {
                       loader: 'css-loader',
                       options: {
                           url: false,
                           modules: false,
                       },
                   },

               ],
           },
       ],
   },
});

exports.loadSASS = ({include, exclude} = {}) => ({
    module: {
        rules: [
            {
                test: /\.scss$/,
                include,
                exclude,

                use: [
                    'style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            url: false,
                            modules: false,
                        },
                    },
                    'sass-loader',
                ],
            },
        ],
    },
});


exports.extractCSS = ({include, exclude, use}) => {
    const plugin = new ExtractTextPlugin({
       filename: 'style/[name].css',
    });

    return {
        module: {
            rules: [
                {
                    test: /\.scss$/,
                    include,
                    exclude,

                    use: plugin.extract({
                        use,
                        fallback: 'style-loader',
                    }),
                },
            ],
        },
        plugins: [plugin],
    };
};

exports.autoprefix = () => ({
    loader: 'postcss-loader',
    options: {
        plugins: () => ([
            require('autoprefixer')(),
        ]),
    },
});